#include "Document.h"
#include "Language.h"
#include <iostream>
using namespace std;

Document :: Document(QWidget* parent) : QWidget(parent), numCell(0) {
	QVBoxLayout* generalLayout = new QVBoxLayout;
	layout = new QVBoxLayout;
	InputTag *init = new InputTag(this, 0, new QString(INSERTTEXT));
	tagInputList.push_back(init);
	layout->addWidget(init);
	generalLayout->addLayout(layout);
	generalLayout->insertStretch(-1, 2);
	setLayout(generalLayout);
	setBackgroundRole(QPalette::Base);
	connect(init, SIGNAL(evaluateText(const QString&, int)), this, SLOT(inputText(const QString&, int)));
}

void Document :: inputText(const QString& text, int code) {
	emit evaluateText(text, code);
}

void Document :: outputText(const QString& text, int code) {
	if (code == tagOutputList.size()) {
		OutputTag *out = new OutputTag(this, tagOutputList.size(), new QString(text));
		tagOutputList.push_back(out);
		layout->addWidget(out);
		InputTag *in = new InputTag(this, tagOutputList.size(), new QString(""));
		tagInputList.push_back(in);
		connect(in, SIGNAL(evaluateText(const QString&, int)), this, SLOT(inputText(const QString&, int)));
		layout->addWidget(in);
	}
	else {
		tagOutputList[code]->setText(new QString(text));
	}
}


